<php>
$this->display(tpl('head',true)); 
if($edit['bold']){
	$bold='checked';
}
if($nid>1){
	$display="style='display:none'";
}
</php>

<style>
	.layui-form-select{
		width: 30%;
	}
	.my-input{
		width: 30%;
		display:  initial;
	}
	.color{
		width: 70px;
	}
	td .layui-form-item{
		margin-bottom: 0;
		border-bottom:1px solid #eee;
	}
	td .layui-form-label{
		width:14.1%;
		padding: 9px 15px;
		min-height: 20px;
		line-height: 20px;
		text-align: left;
		border-right: 1px solid #eee;
	}
	td .layui-input-block{
		margin-left: 0;
	}
	td .layui-input-block:before{
		content:'';
		margin-left:15px
	}
</style>
<script src="/public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<form class="layui-form" method="post" action="">
	<table class="layui-table my-tabel">
		<tbody>
			<tr>
				<td>所属栏目</td>
				<td>
					<select name="post[cid]" lay-filter="ciddb" class="my-input">
		    		<option value="">请选择要发布到的栏目</option>
					<foreach array="allcidDB">
						<php>
							$p_dis="";
							$setting=unserialize($row['setting'])['power'][C('mydb.groupid')];
							if((!$setting['add'] && C('mydb.groupid') !='3') || $row['type'] !==0){
								$p_dis='disabled';
							}
							$selected="";
							if($row['cid']==$cid && !$p_dis){
								$selected=" selected";
							}
						 </php>
					<option type="{{$row['type']}}" mid="{{$row['cmid']}}" value="{{$row['cid']}}" {{$selected;}} {{$p_dis}}>{{$row['levels']}} {{$row['name'] }}</option>
					</foreach>
			    	</select>
				</td>
			</tr>
			<tr>
				<td>标题</td>
				<td>
					<input name="post[title]" value="{{$edit['title']}}"  lay-verify="title" placeholder="请输入标题" class="layui-input my-input" type="text">
					颜色
					<input name="post[color]" id="color" class="layui-input my-input color" type="text" value="{{$edit['color']}}">
					<input name="post[bold]" title="加粗" type="checkbox" value="1" {{$bold}}>
					<div id="picker"></div>
				    <script type="text/javascript">
				    	$("#color").css('background-color','#{{$edit['color']}}');
				    	$("#color").css('color','#fff');
				    	$('#color').colpick({
							layout:'hex',
							submit:0,
							colorScheme:'dark',
							onChange:function(hsb,hex,rgb,el,bySetColor) {
								$(el).css('border-color','#'+hex);
								$(el).css('color','#FFF');
								$(el).css('background-color','#'+hex);
								if(!bySetColor) $(el).val(hex);
							}
						}).keyup(function(){
							$(this).colpickSetColor(this.value);
						});
				    </script>
				    			
				</td>
			</tr>
			<tr>
				<td>关键字</td>
				<td>
					<input name="post[keyword]"  class="layui-input my-input" type="text" value="{{$edit['keyword']}}">
					<p>作为相关文章的索引,如多个用空格隔开</p>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table class="layui-table my-tabel">
						<tbody>
							<tr>
								<td>作者</td>
								<td><input name="post[author]" class="layui-input" type="text" value="{{$edit['author'] }}"></td>
								<td>来源</td>
								<td><input name="post[source]" class="layui-input" type="text" value="{{$edit['source']}}"></td>
								<td>来源网址</td>
								<td><input name="post[source_url]" class="layui-input" type="text" value="{{$edit['source_url']}}"></td>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<table class="layui-table my-tabel">
						<tbody>
							<tr>
								<if condition="$setting['is_comment'] || C('mydb.groupid') =='3'">
								<td>是否禁止评论</td>
								<td><input name="post[is_comment]" class="layui-input" type="checkbox" value="1" title="勾选禁止评论" {{$is_comment[1] }}></td>
								</if>
								<if condition="$setting['is_sell'] || C('mydb.groupid') =='3'">
								
								<td>查看积分</td>
								<td><input name="post[sell_jifen]" class="layui-input" type="text" value="{{$edit['sell_jifen'] }}"></td>
								</if>
								<if condition="$setting['is_pass'] || C('mydb.groupid') =='3'">
								
								<td>查看密码</td>
								<td><input name="post[password]" class="layui-input" type="text" value="{{$edit['password'] }}"></td>
								</if>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
			<tr>
				<td>缩略图</td>
				<td>
					<input name="post[thumb]" id="thumb" class="layui-input  my-input" type="text" value="{{$edit['thumb'] }}">
			    	<button type="button" class="layui-btn layui-btn-normal" id="select_pic">选择图片上传</button>
				</td>
			</tr>
			<if condition="$Custom_Model_Template">
			
			<tr>
				<td colspan="2">
					{{$Custom_Model_Template }}
				</td>
			</tr>
			</if>
			<tr>
				<td>内容</td>
				<td>
					<php>
						$i=0;
						$num=count((array)$cont_query);
					</php>
					<if condition="$num gt 1">
					<div class="page">
						<foreach array="cont_query">
							<php>
								$i++;
							</php>
							<a href="javascript:void(0);" onclick="return content('{{$row['nid'] }}',this);"> 第{{$i }}页</a>
						</foreach>
					</div>
					<script>
						var content_data={{json_encode($cont_query); }};
					</script>
					</if>
					<p>如果是多页在要分页的地方插入##page##</p>
					<textarea name="post[content]" style="height:300px; width: 100%; z-index: 1;" id="content" placeholder="请输入内容" >{{$cont_query['0']['content'] }}</textarea>
					<script type="text/javascript">
						var ue = UE.getEditor('content',{
							zIndex : 900,
							autoHeightEnabled:false,
					       	serverUrl: "/user/index/plugin/ueditor/setting/ueditor_config/",
					      	toolbars: [{{json_encode(C('UEDITOR_CONFIG.function')) ;}}]
						});
						
					</script>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input type="hidden" name="post[aid]" value="{{$edit['aid'] }}" />
					<input type="hidden" id="nid" name="post[nid]" value="{{$cont_query['0']['nid'] }}" />
					<input type="hidden" name="post[mid]" value="{{$mid }}" />
					<input type="hidden" name="post[step]" value="post" />
					<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
				</td>
				<script>
					var _this='';
					function content(nid,THIS){
						if(_this){
							_this.style.backgroundColor='';
							_this.style.color ='';
							_this.style.fontWeight ='';
						}
						console.log(content_data);
						_this=THIS;
						for(var i=0;i<content_data.length;i++){
							if(content_data[i].nid==nid){
								ue.setContent(content_data[i].content);
								$("#nid").val(nid);
							}
						}
						
						
						
						THIS.style.backgroundColor='red';
						THIS.style.color ='#fff';
						THIS.style.fontWeight ='bold';
					}
				</script>
			</tr>
		</tbody>
	</table>	
</div>
</form>
<script>

layui.config({
	version: '{{$NOWTIME }}'
});
layui.use(['upload','form','layer','element','laydate'], function(){
  	var $ = layui.jquery
  	,element = layui.element
  	,upload = layui.upload;
   	var $ = layui.jquery, layer = layui.layer;
	var form = layui.form;
	form.on('select(ciddb)', function(data){
		var type=data.elem.selectedOptions[0].attributes.type.value;
			var mid=data.elem.selectedOptions[0].attributes.mid.value;
		if(type !=0){
			$('.layui-btn').attr("disabled",true);
			alert("只有栏目才可以发布内容，请重新选择");
			return false;
		}else if(data.value > 0){
			window.location.href='/user/articles/add/cid/'+data.value;
			$('.layui-btn').attr("disabled",false); 
		}
	});
	var laydate = layui.laydate;
	laydate.render({
		elem: '#posttime',
		type: 'datetime'
	});
	form.verify({
	    title: function(value){
		    if(value.length < 5){
		        return '标题至少得5个字符';
		    }
	    }
  	});


	
	
	//选完文件后不自动上传
	upload.render({
	    elem: '#select_pic',
	    url: '/user/upfile/up/thumb/1/json/true/',
	    auto: true,
	    bindAction: '#star_upload',
	    before: function(obj){
	    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.code != 0){
		    	layer.msg(res.text);
		    }else{
		      	$('#thumb').val(res.url); 
		    }
		    delete files[index]; //删除对应的文件
	    }
	});
});
</script>
<php> $this->display(tpl('foot',true)); </php>
